//
//  UIView+LCExtension.m
//  LCPackage
//
//  Created by 马军凯 on 2021/6/22.
//  Copyright © 2021 龙采科技集团. All rights reserved.
//

#import "UIView+LCExtension.h"

@implementation UIView (LCExtension)
//上
- (void)setTop:(CGFloat)top {
    CGRect frame = self.frame;
    frame.origin.y = top;
    self.frame = frame;
}
- (CGFloat)top {
    return self.frame.origin.y;
}
//左
- (void)setLeft:(CGFloat)left {
    CGRect frame = self.frame;
    frame.origin.x = left;
    self.frame = frame;
}
- (CGFloat)left {
    return self.frame.origin.x;
}
//下
- (void)setBottom:(CGFloat)bottom {
    CGRect frame = self.frame;
    frame.origin.y = bottom - frame.size.height;
    self.frame = frame;
}
- (CGFloat)bottom {
    return self.frame.origin.y + self.frame.size.height;
}
//右
- (void)setRight:(CGFloat)right {
    CGRect frame = self.frame;
    frame.origin.x = right - frame.size.width;
    self.frame = frame;
}
- (CGFloat)right {
    return self.frame.origin.x + self.frame.size.width;
}
//宽
//- (void)setWidth:(CGFloat)width {
//    CGRect frame = self.frame;
//    frame.size.width = width;
//    self.frame = frame;
//}
//- (CGFloat)width {
//    return self.frame.size.width;
//}
//高
//- (void)setHeight:(CGFloat)height {
//    CGRect frame = self.frame;
//    frame.size.height = height;
//    self.frame = frame;
//}
//- (CGFloat)height {
//    return self.frame.size.height;
//}
//size
- (void)setSize:(CGSize)size {
    CGRect frame = self.frame;
    frame.size = size;
    self.frame = frame;
}
- (CGSize)size {
    return self.frame.size;
}
//origin
- (void)setOrigin:(CGPoint)origin {
    CGRect frame = self.frame;
    frame.origin = origin;
    self.frame = frame;
}
- (CGPoint)origin {
    return self.frame.origin;
}
//centerX
//- (void)setCenterX:(CGFloat)centerX {
//    CGPoint center = self.center;
//    center.x = centerX;
//    self.center = center;
//}
//- (CGFloat)centerX {
//    return self.center.x;
//}
//centerY
//- (void)setCenterY:(CGFloat)centerY {
//    CGPoint center = self.center;
//    center.y = centerY;
//    self.center = center;
//}
//- (CGFloat)centerY {
//    return self.center.y;
//}


- (void)LC_cornerRadius:(CGFloat)Radius {
    self.layer.cornerRadius = Radius;
    self.clipsToBounds = YES;
}

- (void)LC_cornerLineWidth:(CGFloat)Width LineColor:(UIColor *)color {
    self.layer.borderWidth = Width;
    self.layer.borderColor = color.CGColor;
}

//剪切
- (void)LC_cornerRadius:(CGFloat)radius byRoundingCorners:(UIRectCorner)corners {
    //设置切哪个直角
    //    UIRectCornerTopLeft     = 1 << 0,  左上角
    //    UIRectCornerTopRight    = 1 << 1,  右上角
    //    UIRectCornerBottomLeft  = 1 << 2,  左下角
    //    UIRectCornerBottomRight = 1 << 3,  右下角
    //    UIRectCornerAllCorners  = ~0UL     全部角
    //得到view的遮罩路径
    UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:self.bounds byRoundingCorners:corners cornerRadii:CGSizeMake(radius, radius)];
    //创建 layer
    CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
    maskLayer.frame = self.bounds;
    //赋值
    maskLayer.path = maskPath.CGPath;
    self.layer.mask = maskLayer;
}

- (void)addRoundedCorners:(UIRectCorner)corners withRadius:(CGSize)radius {
    UIBezierPath *rounded = [UIBezierPath bezierPathWithRoundedRect:self.bounds byRoundingCorners:corners cornerRadii:radius];
    CAShapeLayer *shape = [[CAShapeLayer alloc] init];
    [shape setPath:rounded.CGPath];
    self.layer.mask = shape;
}

- (void)addRoundedCorners:(UIRectCorner)corners withRadius:(CGSize)radius viewRect:(CGRect)rect {
    UIBezierPath *rounded = [UIBezierPath bezierPathWithRoundedRect:rect byRoundingCorners:corners cornerRadii:radius];
    CAShapeLayer *shape = [[CAShapeLayer alloc] init];
    [shape setPath:rounded.CGPath];
    self.layer.mask = shape;
}
//添加阴影
- (void)addShadowWithColor:(UIColor *)shadowColor {
    self.layer.shadowColor = shadowColor.CGColor;
    self.layer.shadowOffset = CGSizeMake(0, 0);
    self.layer.shadowOpacity = 1;
    self.clipsToBounds = NO;
    self.layer.shadowRadius = 6;
}

//渐变
- (void)addGradientWithStartPoint:(CGPoint)startPoint endPoint:(CGPoint)endPoint startColor:(UIColor *)startColor endColor:(UIColor *)endColor {
    CAGradientLayer *layer = [CAGradientLayer layer];
    layer.frame = self.bounds;
    layer.colors = @[(__bridge id)startColor.CGColor, (__bridge id)endColor.CGColor];
    layer.startPoint = startPoint;
    layer.endPoint = endPoint;
    [self.layer insertSublayer:layer atIndex:0];
}

//xib的view
+ (NSArray *)addNibViewWith:(NSString *)nibName {
    return [[NSBundle mainBundle] loadNibNamed:nibName owner:nil options:nil];
}

@end
